﻿using System;
using System.Windows.Controls;
using System.Windows.Data;

namespace DevKnightlie.WPF.AutoForm.FieldDefinitions
{
    /// <summary>
    /// Field definition which creates a ListBox whose ItemsSource is bound to a model property
    /// </summary>
    public class ListBoxFieldDefinition: BaseFieldDefinition
    {
        #region Methods

        public override void BuildInputControl()
        {
            ListBox listBox = new ListBox()
            {
                Height = 120 // TODO: Default Height should not be a magic number
            };
            if (!String.IsNullOrWhiteSpace(PropertyName))
            {
                Binding itemsSourceBinding = new Binding(PropertyName);
                BindingOperations.SetBinding(listBox, ItemsControl.ItemsSourceProperty, itemsSourceBinding);
            }
            SetupEnabledBinding(listBox);
            ContainerControl = InputControl = listBox;
        }

        #endregion
    }
}
